package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.Yszp;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.YszpMapper;
import com.gfxy.modules.items.service.IYszpService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 艺术作品获全国美展
 * @Author: jeecg-boot
 * @Date:   2021-10-03
 * @Version: V1.0
 */
@Service
public class YszpServiceImpl extends AbstractProjectServiceImpl<YszpMapper, Yszp> implements IYszpService {

	protected int memberCellNum = 3;

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}

	@Override
	protected Yszp getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));
		String classess  = ExcelUtil.formatCell(row.getCell(1));
		String projectName = ExcelUtil.formatCell(row.getCell(2));
		Yszp yszp = new Yszp();
		yszp.setDate(date);
		yszp.setClassess(translateClassess(classess));
		yszp.setProjectName(projectName);
		yszp.setIsPass(0);
		yszp.setTotalScore(this.getTotalScore(yszp));
		return yszp;
	}



	@Override
	public Double getTotalScore(Yszp yszp) {
		double result = 0.0;
		int classess = yszp.getClassess();
		if(classess == 1){
			result = 100	;
		} else if(classess == 2 ) {
			result = 80;
		} else if(classess == 3 ) {
			result = 50;
		} else if(classess == 4 ) {
			result = 30;
		} else if(classess == 5 ) {
			result = 20;
		}
		return result;
	}

	@Override
	public IPage<YszpMemberPage> getYszpMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<YszpMemberPage> page = new Page<>(pageNo,pageSize);
		return page.setRecords(this.baseMapper.selectYszpMemberPageListByYear(date));
	}

	@Override
	public List<YszpMemberPage> getYszpMemberPageListByYear(String date) {
		return this.baseMapper.selectYszpMemberPageListByYear(date);
	}
	private int translateClassess(String classess){
		if(classess == null || classess.equals("")){
			return 0;
		} else if(classess.equals("一等奖")){
			return 1;
		} else if(classess.equals("二等奖")){
			return 2;
		} else if(classess.equals("三等奖")){
			return 3;
		}  else if(classess.equals("优秀奖")){
			return 4;
		}  else if(classess.equals("提名奖")){
			return 5;
		} else {
			return 0;
		}
	}

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(Yszp jxcg)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(jxcg.getClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(YszpMemberPage.class, "classess", String.valueOf(jxcg.getClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}
}
